const sql = require('mssql');
const baseFn = require('../../public/base.js');
/**
 * 
 *公共接口
 */


//  获得所有支付方式

const getAllPayStyle = async (ctx, next) => {
    let selectSql = `SELECT BM,MC FROM BM_JSFS WHERE QY_FLAG = 'T'`;
    let result = await sql.query(selectSql);

    ctx.body = {
        result: result.recordset
    };
}

//  获取打印小票上公司的信息

const getPrintCompanyInfo = async (ctx, next) => {
    try {
        const { bm } = ctx.request.body;
        let selectSql = `SELECT BM.BM,BM.MC,BM.DZ,BM.DH FROM BM_BM BM WHERE BM = '${bm}' AND QY_FLAG = 'T'`;
        let selectResult = await sql.query(selectSql);
        if (selectResult.rowsAffected[0] > 0) {
            ctx.body = { success: true, result: selectResult.recordset }
        } else {
            ctx.body = { success: false }
        }

    } catch (err) {
        ctx.body = { success: false, err }
    }
}




//  获取所有的剂型

const getShopJx = async (ctx, next) => {
    try {
        let selectSql = `SELECT * FROM BM_JX JX WHERE  JX.QY_FLAG = 'T'`;
        let selectResult = await sql.query(selectSql);
        ctx.body = { code: 200, message: '获取数据成功', data: { result: selectResult.recordset } }


    } catch (err) {
        ctx.body = { success: false, err }
    }
}

//  获取所有的经营分类
const getShopJyfl = async (ctx, next) => {
    try {
        let selectSql = `SELECT * FROM BM_JYFW JY WHERE  JY.QY_FLAG = 'T'`;
        let selectResult = await sql.query(selectSql);
        ctx.body = { code: 200, message: '获取数据成功', data: { result: selectResult.recordset } }


    } catch (err) {
        ctx.body = { success: false, err }
    }
}





module.exports = {
    'GET /getAllPayStyle': getAllPayStyle,
    'POST /getPrintCompanyInfo': getPrintCompanyInfo,
    'POST /getShopJx': getShopJx,
    'POST /getShopJyfl': getShopJyfl

}
